#coding=utf-8
#Boa:Dialog:DlgCustType

import wx
from ctrlAider import MyListCtrlDecorator
from product import CDataCustomerType

def create(parent):
    return DlgCustType(parent)

[wxID_DLGCUSTTYPE, wxID_DLGCUSTTYPEBTNNEW, wxID_DLGCUSTTYPELC, 
] = [wx.NewId() for _init_ctrls in range(3)]

class DlgCustType(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGCUSTTYPE, name=u'DlgCustType',
              parent=prnt, pos=wx.Point(524, 214), size=wx.Size(580, 462),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'\u5ba2\u6237\u7c7b\u578b')
        self.SetClientSize(wx.Size(572, 428))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Arial'))
        self.Center(wx.BOTH)

        self.btnNew = wx.Button(id=wxID_DLGCUSTTYPEBTNNEW,
              label=u'\u65b0\u5efa', name=u'btnNew', parent=self,
              pos=wx.Point(8, 8), size=wx.Size(86, 29), style=0)
        self.btnNew.Bind(wx.EVT_BUTTON, self.OnBtnNewButton,
              id=wxID_DLGCUSTTYPEBTNNEW)

        self.lc = wx.ListCtrl(id=wxID_DLGCUSTTYPELC, name=u'lc', parent=self,
              pos=wx.Point(8, 48), size=wx.Size(552, 368),
              style=wx.LC_VRULES | wx.LC_REPORT | wx.LC_HRULES)
        self.lc.Bind(wx.EVT_LEFT_DCLICK, self.OnLcLeftDclick)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        cols = [(CDataCustomerType.fi_id, wx.LIST_FORMAT_LEFT, -1),
                (CDataCustomerType.fi_name, wx.LIST_FORMAT_LEFT, 200)]
                
        self.listCtrl  = MyListCtrlDecorator(self.lc, cols, CDataCustomerType)

    def getSelectStr(self):
        return self.m_str
    
    def OnLcLeftDclick(self, event):
        item = self.lc.GetNextItem(-1, state = wx.LIST_STATE_SELECTED)
        if (item == -1):
            return
        
        self.m_str = self.lc.GetItem(item, 1).GetText()
        
        self.EndModal(wx.ID_OK)
        
    def OnBtnNewButton(self, event):
        dlg = wx.TextEntryDialog(
                self, u'请输入新的客户类型，请注意避免重复：',
                '新建客户类型', '')

        if dlg.ShowModal() == wx.ID_OK:
            val = dlg.GetValue()
            CDataCustomerType.add(val)
            self.listCtrl.refresh()
